<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/js/layui/css/layui.css" />
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="demoTable">
    <label class="layui-form-label">日期范围</label>
    <div class="layui-inline" id="test6">
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="startTime" id="begin" class="layui-input" placeholder="开始日期">
        </div>
        <div class="layui-form-mid">-</div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off"name="endTime"  id="end" class="layui-input" placeholder="结束日期">
        </div>
    </div>
    <button class="layui-btn" id="searchBtn" data-type="reload">搜索</button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<!-- 自定义的控件 -->
<div id="toolbar" style="display: none; ">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-sm" id="excelDown" lay-event="excelDown"><i class=" layui-icon layui-icon-download-circle">Excel下载</i></button>
        <button type="button" class="layui-btn" id="test1"lay-event="upload">
            <i class="layui-icon">&#xe67c;</i>上传
        </button>
    </div>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="/js/jquery-3.2.1.js" charset="utf-8"></script>
<script src="/js/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use(['table','layer','jquery','laydate','upload'], function(){
        var table = layui.table;
        var $=layui.jquery;
        var laydate = layui.laydate;
        var upload = layui.upload;
        //日期范围
        laydate.render({
            elem: '#test6'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            ,range: ['#startTime', '#endTime']
        });


        table.render({
            elem: '#test'
            , url: '/syslog/list'
            //,height: document.body.clientHeight-60
            ,page: true //开启分页
            , id: 'testReload'
            , cols: [[
                {field:'userid', title:'账户', width:'15%'}
                ,{field:'module', title:'模块', width:'15%'}
                ,{field:'method', title:'方法', width:'15%'}
                ,{field:'responseDate', title:'执行时长',templet: function(d){ return  d.responseDate +'ms' }, width:'10%'}
                ,{field:'ip', title:'访问IP', width:'15%'}
                ,{field:'dates', title:'访问时间',templet:"<div>{{layui.util.toDateString(d.dates,'yyyy-MM-dd HH:mm:ss')}}</div>", width:'15%'}
                ,{field:'commit', title:'执行结果', width:'15%'}
            ]]
            ,toolbar:'#toolbar',//表格头信息
            parseData: function (rs) {//数据格式解析
                if (rs.code == 200) {
                    return {
                        "code": rs.code,
                        "msg": rs.msg,
                        "count": rs.data.total,
                        "data": rs.data.list
                    }
                }
            },
            response: {	// 设置响应码
                statusCode: 200 //规定成功的状态码，默认：0
            }
        });

        //上传
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/syslog/upload' //上传接口
            ,accept:"file"
            ,done: function(res){
                alert("上传完毕回调:");
                console.log(res);
                //上传完毕回调
            }
            ,error: function(){
                console.log("请求异常回调");
                //请求异常回调
            }
        });
        //Excel导出
        $("#excelDown").click(function(){
            var param="";
            if($("#startTime").val()){
               param = "?startTime="+$("#startTime").val()+"&endTime="+$("#endTime").val()
           }
            location.href = "/syslog/selectListExcel"+param;
        });

        var $ = layui.$, active = {
            reload: function () {
                var name = $('#name');
                var phone = $('#phone');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        "name": name.val(),
                        "phone": phone.val()
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

</body>
</html>